#pragma once
#include"HuffmanTree.hpp"
#include"Common.h"

#include<string>
using std::string;

struct ByteInfo
{
	uch _ch;
	size_t _appearCount;
	std::string _chCode;
	ByteInfo(size_t appearCount=0)
		: _appearCount(appearCount)
	{}
	ByteInfo operator+(const ByteInfo& other)const
	{
		return ByteInfo(_appearCount + other._appearCount);
	}
	bool operator>(const ByteInfo& other)const
	{
		return _appearCount > other._appearCount;
	}
	bool operator!=(const ByteInfo& other)const
	{
		return _appearCount != other._appearCount;
	}
	bool operator==(const ByteInfo& other)const
	{
		return _appearCount == other._appearCount;
	}
};

class FileCompressHuffman
{
public:
	FileCompressHuffman();
	void CompressFile(const string& filePath);
	void UNCompressFile(const string& filePath);
private:
	void GenerateHuffmanCode(HuffmanTreeNode<ByteInfo>* root);
	void WriteHeadInfo(const string& filePath, FILE* fOut);
	string GetFilePostfix(const string& filePath);
	void GetLine(FILE* fIn,string& strInfo);
	std::vector<ByteInfo> _fileInfo;

};